package cn.vivi.oss.controller;

import cn.vivi.common.util.Result;
import cn.vivi.oss.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Objects;

@RestController
@RequestMapping("oss")
public class OssController {

    @Autowired
    private OssService ossService;

    @PostMapping("upload")
    public Result<String> uploadFile(MultipartFile file) {
        String fileUrl = ossService.uploadFile(file);
        if (Objects.isNull(fileUrl)) {
            return Result.error("文件上传失败");
        }
        return Result.success(fileUrl);
    }

    @DeleteMapping("delete")
    public Result<Boolean> deleteFile(String filePath) {
        return ossService.deleteFile(filePath) ? Result.success(): Result.error("删除文件失败");
    }

}
